﻿using iMES.Custom.Services;
using iMES.Entity.DomainModels;
using iMES.Inventory.IRepositories;
using iMES.Inventory.IServices;
using iMES.Warehouse.IServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace iMES.Inventory.Controllers
{
    public partial class Inventory_SotreController
    {
        private readonly IView_InventoryStoreServices _service;
        private readonly IHttpContextAccessor _accessor;
        private readonly IView_StoreDetailsRepositories _storeDetailsRepositories;

        [ActivatorUtilitiesConstructor]
        public Inventory_SotreController(
            IView_InventoryStoreServices service,
            IHttpContextAccessor httpContextAccessor,
            IView_StoreDetailsRepositories storeDetailsRepositories
        )
        : base(service)
        {
            _service = service;
            _accessor = httpContextAccessor;
            _storeDetailsRepositories = storeDetailsRepositories;
        }


        [Route("getStoreDtlis"), HttpGet]
        public async Task<IActionResult> getStoreDtlis(int StoreId)
        {
            var rows = await _storeDetailsRepositories.FindAsIQueryable(x => x.WareHouseBill_Id == StoreId).ToListAsync();
            List<Base_Product> storelist = Base_ProductService.GetStoreNumber();
            for (int i = 0; i < rows.Count; i++)
            {
                if (storelist.Exists(x => x.Product_Id == rows[i].Product_Id))
                {
                    rows[i].InventoryQty=storelist.Find(x=>x.Product_Id==rows[i].Product_Id).InventoryQty;
                }
                else
                {
                    rows[i].InventoryQty = 0;
                }
            }
            return JsonNormal(rows);
        }
    }
}
